package com.yerbamateprimer.action.user.impl;

import java.io.Serializable;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.google.common.base.Preconditions;
import com.yerbamateprimer.action.user.AsynchronousUserAction;
import com.yerbamateprimer.model.User;

/**
 * This action is useful
 * to send an invite a user 
 * to the round user action 
 * to the server.
 * 
 * @author Matias Liwski
 * @version 1.0
 */
public class InviteUserToRoundUserAction implements AsynchronousUserAction, Serializable {
	private static final long serialVersionUID = 1515369939107408463L;
	private User user;
	private User invitedUser;

	/**
	 * @param user The user that want to execute this action.
	 * @param invitedUser The user to invite.
	 */
	public InviteUserToRoundUserAction(User user, User invitedUser) {
		setUser(user);
		setInvitedUser(invitedUser);
		Preconditions.checkArgument(!this.invitedUser.equals(this.user), "The user couldn't invite himself ( user: " + this.user + " ).");
	}

	/**
	 * This class has to be implemented at the action decorator.
	 * 
	 * @see com.yerbamateprimer.action.user.UserAction#execute()
	 */
	public void execute() {
	}

	public void setInvitedUser(User user) {
		Preconditions.checkArgument(user != null, "This action needs an invited user to execute it.");
		this.invitedUser = user;
	}

	public User getInvitedUser() {
		return this.invitedUser;
	}

	/* (non-Javadoc)
	 * @see com.yerbamateprimer.action.user.UserAction#setUser(com.yerbamateprimer.model.User)
	 */
	@Override
	public void setUser(User user) {
		Preconditions.checkArgument(user != null, "This action needs a user to execute it.");
		this.user = user;
	}

	/* (non-Javadoc)
	 * @see com.yerbamateprimer.action.user.UserAction#getUser()
	 */
	@Override
	public User getUser() {
		return this.user;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE, false, false);
	}
}